/*
Copyright 2008, 2009 Joonas Lehtolahti

This file is part of Openfire-C.

Openfire-C is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Openfire-C is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with Openfire-C.  If not, see <http://www.gnu.org/licenses/>.
*/

/* XfirePacketAnalyzeExt.inc is to be included using #include after defining
 * _XFABT and _XFABP (parameter types and parameters)
 */
{
	struct XfNetworkHandlerList *handlerlist = XfireAnalyze_FindNetworkHandlerList(inst->network->network_handlers, packet->pid);
	
	if (handlerlist) {
		typedef unsigned int XFNHFUNC_EXT(XFINST, unsigned int, _XFABT, void*);
		
		ListNode *handler = handlerlist->funcs->first;
		struct XfNetworkHandler *nhandler;
		XFNHFUNC_EXT *handler_func;
		unsigned int handler_ret;
		
					
		if (handler) {
			retval |= XFIH_EXTERNAL;
		}
		while (handler) {
			nhandler = (struct XfNetworkHandler *)handler->x;
			handler_func = (XFNHFUNC_EXT *)nhandler->func;
			handler_ret = handler_func(inst, packet->pid, _XFABP, nhandler->freedata);
			if (handler_ret & XFNH_NOHANDLE) {
				retval &= ~XFIH_HANDLED;
			}
			if (handler_ret & XFNH_NOITERATION) {
				retval |= XFIH_PENDING;
				break;
			}
			if (handler_ret == XFNH_FATAL) return XFIH_FATAL;
			retval |= (handler_ret & XFNH_USER_MASK);
			handler = handler->next;
		}
	}
}
#undef _XFABT
#undef _XFABP
